﻿package mortal.game.view.autoFight.render
{
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.net.*;
    import mortal.component.gconst.*;
    import mortal.game.view.autoFight.data.*;
    import mortal.game.view.common.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.skill.panel.render.*;

    public class AFAssistSkillRender extends GSprite
    {
        private var _item:SkillItem;
        private var _myData:AFSkillData;
        private var _txt:GTextFiled;
        private var _txtInput:GTextInput;
        private var _txtAuto:GTextFiled;

        public function AFAssistSkillRender()
        {
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            this._myData = param1 as AFSkillData;
            if (this._myData.info == null || !this._myData.info.learned)
            {
                this.mouseEnabled = false;
                DisplayUtil.removeMe(this._txtInput);
                DisplayUtil.removeMe(this._txtAuto);
                this._item.isShowToolTip = false;
                return;
            }
            this._item.isShowToolTip = true;
            this.mouseEnabled = true;
            if (this._txtInput.parent == null)
            {
                this.addChild(this._txtInput);
            }
            if (this._txtAuto.parent == null)
            {
                this.addChild(this._txtAuto);
            }
            this._item.skillInfo = this._myData.info;
            if (this._myData.isActive)
            {
                this._item.filters = [];
            }
            else
            {
                this._item.filters = [FilterConst.colorFilter];
            }
            this._txt.text = this._myData.titleName;
            this._txtAuto.text = this._myData.strUse;
            if (this._myData.info.tSkill.hookType == SkillHookType.buff)
            {
                DisplayUtil.removeMe(this._txtInput);
                this._txtAuto.x = this._txtInput.x;
            }
            else
            {
                this._txtInput.text = this._myData.value.toString();
                this.addChild(this._txtInput);
                this._txtAuto.x = this._txtInput.x + this._txtInput.width;
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UICompomentPool.getUICompoment(SkillItem) as SkillItem;
            this._item.y = 6;
            this.addChild(this._item);
            this._item.isDragAble = false;
            this._item.isDropAble = false;
            this._item.isThrowAble = false;
            this._item.isShowFreezingEffect = false;
            this._item.isShowLeftTimeEffect = false;
            this._item.isShowToolTip = true;
            this._item.setSize(42, 42);
            this._item.setBg();
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.leading = 6;
            this._txt = UIFactory.gTextField("", 45, this._item.y, 100, 20, this, _loc_1);
            this._txt.multiline = true;
            this._txt.wordWrap = true;
            this._txtInput = UIFactory.gTextInput(this._item.x + 45, this._item.y + 17, 35, 20, this);
            this._txtInput.maxChars = 3;
            this._txtInput.restrict = "0-9";
            this._txtAuto = UIFactory.gTextField(Language.getString(21251), this._txtInput.x + this._txtInput.width, this._txtInput.y, 66, 20, this);
            this._txtInput.configEventListener(TextEvent.TEXT_INPUT, this.valueChangeHandler);
            this._item.configEventListener(MouseEvent.CLICK, this.selectedChangeHandler);
            return;
        }// end function

        private function selectedChangeHandler(event:MouseEvent) : void
        {
            if (this._myData.info == null)
            {
                return;
            }
            this._myData.isActive = !this._myData.isActive;
            this.data = this._myData;
            return;
        }// end function

        private function valueChangeHandler(event:TextEvent) : void
        {
            var nextFrameValueChange:Function;
            var evt:* = event;
            nextFrameValueChange = function () : void
            {
                _myData.value = parseInt(_txtInput.text);
                data = _myData;
                return;
            }// end function
            ;
            CallLater.addCallBack(nextFrameValueChange);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._item.dispose(param1);
            this._item = null;
            this._txt.dispose(param1);
            this._txt = null;
            this._txtInput.dispose(param1);
            this._txtInput = null;
            this._txtAuto.dispose(param1);
            this._txtAuto = null;
            return;
        }// end function

    }
}
